package com.nut.spp.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.spp.api.req.GoodsQueryReq;
import com.nut.spp.common.Result;
import com.nut.spp.entity.Goods;
import com.nut.spp.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/admin/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    public Result<IPage<Goods>> listPage(GoodsQueryReq req) {
        return goodsService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Goods> detail(@PathVariable Integer id) {
        return goodsService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Goods goods) {

//        goods.setShopId(0);
//        goods.setShopName("自营");

        return goodsService.add(goods);
    }

    @PutMapping
    public Result update(@RequestBody Goods goods) {
        return goodsService.updateById(goods);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return goodsService.deleteByIds(ids);
    }

}